#-------------------------------------------------------------------------------
# Name:        LogFile
# Purpose:
#
# Author:      Mr.Junz-N
#
# Created:     06/12/2012
# Copyright:   (c) Mr.Junz-N 2012
# Licence:     <your licence>
#-------------------------------------------------------------------------------
from Bootstrap import conf
import glob
import os

#////////////////////////////////////////////
# Test tu cac file thuc muc Log
#
#
#////////////////////////////////////////////
class LogFiles:
    """ Thuc hien viec lay cac file log tu thu muc da config"""
    dirLog = conf.FILE_PATH_DATA
    def __init__(self):
        pass

    def getListFileLogs(self):
        os.chdir(self.dirLog)
        self.listFiles = glob.glob("*.log")
        return self.listFiles

    @staticmethod
    def testStatic():
        return 1

    def DetermineTypeOfLog(self, logFileName):
        first_LineLogs = str(self.getFirstLineLog(logFileName))
        print first_LineLogs
        if (first_LineLogs.startswith("#Software")):
            return "IIS"
        else:
            return "unknow"

    def getListLogs(self, logFileName):
        filePath = self.dirLog + "\\" + logFileName
        fp = open( filePath,'r')
        listLogs = fp.readlines()
        return listLogs
    def getFirstLineLog(self, logFileName):
        filePath = self.dirLog + "\\" + logFileName
        fp = open(filePath,'r')
        first_LineLogs = fp.readline()
        return first_LineLogs



if __name__ == '__main__':
    logFiles  = LogFiles()
    listFiles = logFiles.getListFileLogs()
    print logFiles.dirLog
    for file in listFiles:
        print logFiles.DetermineTypeOfLog(file)
